package com.baozi.demo.item.cart

import android.widget.CheckBox

import com.baozi.demo.R
import com.baozi.demo.activity.CartAt
import com.baozi.treerecyclerview.base.ViewHolder
import com.baozi.treerecyclerview.factory.ItemHelperFactory
import com.baozi.treerecyclerview.item.TreeItem
import com.baozi.treerecyclerview.item.TreeSelectItemGroup

import java.util.ArrayList

/**
 * Created by a123 on 2018/6/5.
 */
class CartGroupItem2 : TreeSelectItemGroup<CartBean.CartBean2>() {

    override fun initChild(data: CartBean.CartBean2): List<TreeItem<*>>? {
        val list = ArrayList<CartBean.CartBean2.CartBean3>()
        for (i in 0 until data.childSum) {
            list.add(CartBean.CartBean2.CartBean3(3))
        }
        return ItemHelperFactory.createItems(list, treeParentItem = this)
    }

    override fun getLayoutId(): Int {
        return R.layout.item_cart_group
    }



    override fun onBindViewHolder(viewHolder: ViewHolder) {
        viewHolder.setText(R.id.cb_ischeck, "笔记本(二级)")
        viewHolder.setChecked(R.id.cb_ischeck, isSelect)
        viewHolder.getView<CheckBox>(R.id.cb_ischeck).setOnClickListener { v ->
            selectAll(!isSelectAll, true)
            (viewHolder.itemView.context as CartAt).notifyPrice()
        }
        viewHolder.itemView.setPadding(20, 0, 0, 0)
    }


}
